<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>书店客服平台</title>
  <style>
    /* CSS样式开始 */
    * {
      box-sizing: border-box;
    }

    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f4f4f4;
    }

    header {
      background-color: #333;
      color: white;
      text-align: center;
      padding: 20px;
    }

    main {
      padding: 20px;
    }

    #chat-section {
      background-color: white;
      border-radius: 5px;
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
      padding: 15px;
    }

    #chat-window {
      height: 300px;
      overflow-y: auto;
      border: 1px solid #ccc;
      margin-bottom: 10px;
      padding: 10px;
    }

   .message {
      margin-bottom: 10px;
      padding: 8px 12px;
      border-radius: 4px;
      max-width: 70%;
    }

   .user-message {
      background-color: #007bff;
      color: white;
      float: right;
    }

   .agent-message {
      background-color: #ccc;
      color: #333;
      float: left;
    }

   .clearfix::after {
      content: "";
      display: table;
      clear: both;
    }

    #message-form {
      display: flex;
    }

    #message-input {
      flex: 1;
      padding: 8px;
      border: 1px solid #ccc;
      border-radius: 4px;
    }

    button {
      padding: 8px 15px;
      background-color: #007bff;
      color: white;
      border: none;
      cursor: pointer;
      border-radius: 4px;
      margin-left: 10px;
    }
    /* CSS样式结束 */
  </style>
</head>

<body>
  <header>
    <h1>网上书店客服服务平台</h1>
  </header>
  <main>
    <section id="chat-section">
      <div id="chat-window">
        <!-- 聊天记录展示区域 -->
      </div>
      <form id="message-form">
        <input type="text" id="message-input" placeholder="请输入您的消息" />
        <button type="submit">发送</button>
      </form>
    </section>
  </main>
  <script>
    // JavaScript交互逻辑开始
    const messageForm = document.getElementById('message-form');
    const messageInput = document.getElementById('message-input');
    const chatWindow = document.getElementById('chat-window');

    // 获取当前时间并格式化的函数
    function getCurrentTime() {
      const now = new Date();
      const hours = now.getHours().toString().padStart(2, '0');
      const minutes = now.getMinutes().toString().padStart(2, '0');
      return `${hours}:${minutes}`;
    }

    messageForm.addEventListener('submit', function (e) {
      e.preventDefault();
      const messageText = messageInput.value;
      if (messageText.trim()!== '') {
        // 创建用户消息元素并添加到聊天窗口
        const userMessageDiv = document.createElement('div');
        userMessageDiv.classList.add('message', 'user-message');
        userMessageDiv.innerHTML = `
          <p><strong>您（${getCurrentTime()}）：</strong> ${messageText}</p >
        `;
        chatWindow.appendChild(userMessageDiv);

        // 模拟客服回复（实际需对接后端获取真实回复）
        setTimeout(() => {
          const agentReply = "您好，很高兴为您服务，请问有什么可以帮您的？";
          const agentMessageDiv = document.createElement('div');
          agentMessageDiv.classList.add('message', 'agent-message');
          agentMessageDiv.innerHTML = `
            <p><strong>客服（${getCurrentTime()}）：</strong> ${agentReply}</p >
          `;
          chatWindow.appendChild(agentMessageDiv);
        }, 1000);

        messageInput.value = '';
      }
    });
    // JavaScript交互逻辑结束
  </script>
</body>

</html>